package streaimg

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds,StreamingContext}

object SparkStreamingData1_1 {
  def main(args: Array[String]): Unit = {
    val sparkConf = new
        SparkConf().setMaster("local[2]").setAppName("NetworkWorkCount")
    val ssc = new StreamingContext(sparkConf, Seconds(5))
    val lines = ssc.socketTextStream("172.16.104.6", 9999)
    val words = lines.flatMap(_.split(" "))
    val pairs = words.map(word => (word, 1))
    val wordCounts = pairs.reduceByKey(_ + _)
   wordCounts.print()
   ssc.start()
   ssc.awaitTermination()
    }
  }
